﻿using System;
using System.Web;
using Bintje;

public partial class userDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (this.Page.User.Identity.Name == null || this.Page.User.Identity.Name == ""|| AppUser.currUser() == 0)
            {
                Response.Redirect("../login.aspx?Retuenurl=" + Request.Url.ToString());
            }
            int uid = 0;
            if (AppUser.currUser() > 0)
            {
                pnluser.Visible = true;
                myTrails1.IsEdit = true;
            }
            if (Request["uid"] != null)
            {
                int.TryParse(Request["uid"], out uid);
                if (Request["uid"] == AppUser.currUser().ToString() && AppUser.currUser() > 0)
                {
                    pnluser.Visible = true;
                    myTrails1.IsEdit = true;
                }
                else
                {
                    pnluser.Visible = false;
                    myTrails1.IsEdit = false;
                }
            }
            else
            {
                int.TryParse(Session["UserId"].ToString(), out uid);
            }
            if (uid > 0)
            {
                //fillControl(uid);
                //userProfile1.UserId = uid;
                userProfile1.User = fillControl(uid);
                myTrails1.UserId = uid;
                ltrUsername.Text = AppUser.getUsernameById(uid) + "'s Profile";
            }
            if (Request["comm"] != null)
            {
                lblMsg.Visible = true;
            }
            
        }
    }

    public Bintje.User fillControl(int uid)
    {
        try
        {
            Bintje.bintje.imageoSession session = (Bintje.bintje.imageoSession)Session["Session"];
            Bintje.User user = new Bintje.User(session);
            user.LoadDetails();
            myImages.Text = "";

            if (!string.IsNullOrEmpty(user.ImageUrl))
                imgMain.ImageUrl = user.ImageUrl;
            else
                imgMain.ImageUrl = "~/sitefiles/Get-Thumbnail.aspx?f=~/images/no_image.gif&w=170&h=170";

            if (string.IsNullOrEmpty(user.ImageUrl))
                hprEditPhotos.Text = "Add Photo";
            /*
            for(int i=0;i<uimg.Length;i++)
            {
                if (i == 0)
                {                
                    imgMain.ImageUrl = string.Format("~/sitefiles/Get-Thumbnail.aspx?f=~/Upload/users/tn/{0}&w=170&h=170", uimg[i].Image); 
                }
                myImages.Text += "<li><img src='../Upload/users/tn/"+uimg[i].Image+"' width='75' onclick='changeimg(this)' height='75' alt='' /></li>";
            }
            */
            //lbluserFriends.Text = AppUser.getUsernameById(uid) + "'s friends";
            lblUserPhotos.Text = (!string.IsNullOrEmpty(user.NickName) ? user.NickName : user.Login) + "'s photos";
            return user;

        }
        catch (Exception)
        {
            return null;
        }
    }
}
